<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // Promise.race()
        let time=0;
        let getUserInfo=function(){
            return new Promise((resolve,reject)=>{
                setTimeout(() => {
                    resolve('姓名：汉庭')
                }, Math.floor(Math.random()*400));
            })
        }
        let showUserInfo=function(){
            return getUserInfo().then(info=>{
                console.log('用户信息',info);
                return true;
            })
        }
        let timeout = function(time){
            return new Promise((resolve)=>{
                setTimeout(() => {
                    resolve();
                }, time);
            })
        }
        let showToast=function(){
            time= +new Date();
            console.log('show loading..')
        }

        let hideToast=function(){
            console.log('hide loading' + (+new Date()-time))
        }
        Promise.race([showUserInfo(),timeout(200)]).then((display)=>{
            console.log(display,'---');
            if(!display){
                showToast();
                Promise.all([showUserInfo(),timeout(200)]).then(()=>{
                    hideToast();
                })
            }
        })
    </script>
</body>
</html>